<template>
  <Form ref="caseValidate" :model="caseForm" :rules="ruleCaseForm" :label-width="80">
    <FormItem label="用例名称" prop="name">
      <Input v-model="caseForm.name" placeholder="请输入"/>
    </FormItem>
    <FormItem label="所属环境" prop="env_id">
      <Select v-model="caseForm.env_id">
        <Option v-for="item in envList" :value="item.id" :key="item.id">{{ item.name }}</Option>
      </Select>
    </FormItem>
    <FormItem label="所属接口" prop="interface_id">
      <Select v-model="caseForm.interface_id">
        <Option v-for="item in InterfaceList" :value="item.id" :key="item.id">{{ item.name }}</Option>
      </Select>
    </FormItem>
    <FormItem label="接口参数">
      <Input v-model="caseForm.query" placeholder="query参数"/>
    </FormItem>
    <FormItem label="备注" prop="remark">
      <Input v-model="caseForm.remark" type="textarea" :rows="4" placeholder="请输入"/>
    </FormItem>
  </Form>
</template>

<script>
import {apiAll, envs} from "@/utils/api";

export default {
  name: "basis",
  props:{
    caseForm: Object
  },
  data() {
    return {
      envList: [],
      InterfaceList: [],
      ruleCaseForm: {
        name: [
          {required: true, message: '用例名称必填', trigger: 'blur'}
        ],
        env_id: [
          {required: true, message: '所属环境必填', trigger: 'change', type: 'number'}
        ],
        interface_id: [
          {required: true, message: '所属接口必填', trigger: 'change', type: 'number'}
        ],
      }
    }
  },
  watch: {
    'caseForm':{
      deep:true,
      immediate: true,
      handler(v){
        // console.log(v, 888888)
      }
    }
  },
  created() {
    this.handleGetEnvs();
    this.handleGetApi();
  },
  methods: {
    handleGetEnvs(){
      const obj = {
        project_id: parseInt(localStorage.getItem("project_id"))
      }
      envs(obj).then(res=>{
        this.envList = res.data.data;
      })
    },
    handleGetApi(){
      const obj = {
        project_id: parseInt(localStorage.getItem("project_id"))
      }
      apiAll(obj).then(res=>{
        this.InterfaceList = res.data.data;
      })
    }
  }
}
</script>

<style scoped>

</style>
